import request from '@/utils/request'

import type { ResponsePermission, MenuParams } from './type'

enum Api {
  getPermissionList = '/admin/acl/permission',
  // 添加
  addPermission = '/admin/acl/permission/save/',
  // 更新
  updatePermission = '/admin/acl/permission/update/',
  // 删除
  deleteCurPermission = '/admin/acl/permission/remove/',
}

export const reqPermissionList = () => {
  return request.get<any, ResponsePermission>(Api.getPermissionList)
}

export const reqAddOrUpdatePermission = (data: MenuParams) => {
  if (data.id) return request.put<any, any>(Api.updatePermission, data)
  return request.post<any, any>(Api.addPermission, data)
}

export const reqDeleteCurPermission = (id: number) => {
  return request.delete<any, any>(Api.deleteCurPermission + id)
}
